﻿using Core.Domain.Entities;
using Core.Migrations.Extensions;
using FluentMigrator;

namespace Infrastructure.Persistence.Migrations.Users;

[Migration(202508211010)]
public class CreateColumn : ForwardOnlyMigration
{
    public override void Up()
    {
        Alter.Table(typeof(User).GetTableName())
          .InSchema(SchemaNames.Identity)
          .AddColumn("TenantId").AsString(100).Nullable().WithColumnDescription("租户标识")
          .AddColumn("AvatarUrl").AsString(512).Nullable().WithColumnDescription("头像地址")
          .AddColumn("AvatarContentType").AsString(64).Nullable().WithColumnDescription("头像文件类型")
          .AddColumn("PhoneNumber").AsString(32).Nullable().WithColumnDescription("手机号码")
          .AddColumn(MigrationExpressions.ColumnNameFor<User>(nameof(User.PhoneNumberConfirmed))).AsBoolean().Nullable().WithColumnDescription("手机确认")
          .AddColumn(MigrationExpressions.ColumnNameFor<User>(nameof(User.TwoFactorEnabled))).AsBoolean().Nullable().WithColumnDescription("开启双因子确认")
          .AddColumn("AccessFailedCount").AsInt32().Nullable().WithColumnDescription("登录失败次数")
          .AddColumn("LockoutEnd").AsDateTimeOffset().Nullable().WithColumnDescription("解锁时间")
          .AddColumn("IsLocked").AsBoolean().Nullable().WithColumnDescription("是否锁定")
          .AddColumn(MigrationExpressions.ColumnNameFor<User>(nameof(User.Username))).AsString(64).Nullable().WithColumnDescription("用户名")
          .AddColumn(MigrationExpressions.ColumnNameFor<User>(nameof(User.NormalizedUserName))).AsString(64).Indexed("IX_Users_NormalizedUserName").Nullable().WithColumnDescription("用户名称")
          .AddColumn(MigrationExpressions.ColumnNameFor<User>(nameof(User.Nickname))).AsString(64).Nullable().WithColumnDescription("昵称")
          .AddColumn(MigrationExpressions.ColumnNameFor<User>(nameof(User.Email))).AsString(256).Nullable().WithColumnDescription("邮箱")
          .AddColumn(MigrationExpressions.ColumnNameFor<User>(nameof(User.EmailConfirmed))).AsBoolean().Nullable().WithColumnDescription("邮箱确认")
          .AddColumn(MigrationExpressions.ColumnNameFor<User>(nameof(User.NormalizedEmail))).AsString(256).Indexed("IX_Users_NormalizedEmail").Nullable().WithColumnDescription("邮箱")
          .AddColumn(MigrationExpressions.ColumnNameFor<User>(nameof(User.PasswordHash))).AsString(256).Nullable().WithColumnDescription("密码哈希")
          .AddColumn(MigrationExpressions.ColumnNameFor<User>(nameof(User.SecurityStamp))).AsString(64).Nullable().WithColumnDescription("安全印章")
          .AddColumn(MigrationExpressions.ColumnNameFor<User>(nameof(User.ConcurrencyStamp))).AsString(64).Nullable().WithColumnDescription("并发戳记"); 
    }
}
